package com.newenergy.wisehome.gateway.common;

import com.newenergy.wisehome.data.bean.BLDeviceInfo;

import cn.com.broadlink.family.params.BLFamilyDeviceInfo;
import cn.com.broadlink.sdk.data.controller.BLDNADevice;

public class BLModelUtil {

    public static BLDNADevice toDNADevice(BLDeviceInfo blDeviceInfo) {
        BLDNADevice bldnaDevice = new BLDNADevice();
        bldnaDevice.setDid(blDeviceInfo.getDid());
        bldnaDevice.setMac(blDeviceInfo.getMac());
        bldnaDevice.setId(blDeviceInfo.getTerminalId());
        bldnaDevice.setKey(blDeviceInfo.getKey());
        bldnaDevice.setLock(blDeviceInfo.isLock());
        bldnaDevice.setPid(blDeviceInfo.getPid());
        bldnaDevice.setpDid(blDeviceInfo.getPdid());
        bldnaDevice.setName(blDeviceInfo.getName());
        bldnaDevice.setPassword(blDeviceInfo.getPassword());
        bldnaDevice.setType(blDeviceInfo.getDeviceType());
        bldnaDevice.setExtend(blDeviceInfo.getExtend());
        return bldnaDevice;
    }

    public static BLDNADevice toDNADevice(BLFamilyDeviceInfo familyDeviceInfo) {
        BLDNADevice bldnaDevice = new BLDNADevice();
        bldnaDevice.setName(familyDeviceInfo.getName());
        bldnaDevice.setDid(familyDeviceInfo.getDid());
        bldnaDevice.setMac(familyDeviceInfo.getMac());
        bldnaDevice.setId(familyDeviceInfo.getTerminalId());
        bldnaDevice.setKey(familyDeviceInfo.getAeskey());
        bldnaDevice.setLock(familyDeviceInfo.isLock());
        bldnaDevice.setPid(familyDeviceInfo.getPid());
        bldnaDevice.setpDid("");

        bldnaDevice.setPassword(familyDeviceInfo.getPassword());
        bldnaDevice.setType(familyDeviceInfo.getType());
        bldnaDevice.setExtend(familyDeviceInfo.getExtend());
        return bldnaDevice;
    }

    public static BLDeviceInfo toBLDeviceInfo(BLDNADevice bldnaDevice) {
        BLDeviceInfo blDeviceInfo = new BLDeviceInfo();
        blDeviceInfo.setDid(bldnaDevice.getDid());
        blDeviceInfo.setMac(bldnaDevice.getMac());
        blDeviceInfo.setTerminalId(bldnaDevice.getId());
        blDeviceInfo.setKey(bldnaDevice.getKey());
        blDeviceInfo.setLock(bldnaDevice.isLock());
        blDeviceInfo.setPid(bldnaDevice.getPid());
        blDeviceInfo.setPdid(bldnaDevice.getpDid());
        blDeviceInfo.setName(bldnaDevice.getName());
        blDeviceInfo.setPassword(bldnaDevice.getPassword());
        blDeviceInfo.setDeviceType(bldnaDevice.getType());
        blDeviceInfo.setExtend(bldnaDevice.getExtend());
        return blDeviceInfo;
    }


    public static BLDeviceInfo toBLDeviceInfo(BLFamilyDeviceInfo familyDeviceInfo) {
        BLDeviceInfo blDeviceInfo = new BLDeviceInfo();
        blDeviceInfo.setDid(familyDeviceInfo.getDid());
        blDeviceInfo.setMac(familyDeviceInfo.getMac());
        blDeviceInfo.setTerminalId(familyDeviceInfo.getTerminalId());
        blDeviceInfo.setKey(familyDeviceInfo.getAeskey());
        blDeviceInfo.setLock(familyDeviceInfo.isLock());
        blDeviceInfo.setPid(familyDeviceInfo.getPid());
        blDeviceInfo.setPdid("");
        blDeviceInfo.setName(familyDeviceInfo.getName());
        blDeviceInfo.setPassword(familyDeviceInfo.getPassword());
        blDeviceInfo.setDeviceType(familyDeviceInfo.getType());
        blDeviceInfo.setExtend(familyDeviceInfo.getExtend());
        return blDeviceInfo;
    }

    public static BLFamilyDeviceInfo toFamilyDeviceInfo(BLDNADevice bldnaDevice) {
        BLFamilyDeviceInfo deviceInfo = new BLFamilyDeviceInfo();
        if (bldnaDevice == null) {
            return deviceInfo;
        }
        deviceInfo.setDid(bldnaDevice.getDid());
        deviceInfo.setPid(bldnaDevice.getPid());
        deviceInfo.setMac(bldnaDevice.getMac());
        deviceInfo.setName(bldnaDevice.getName());
        deviceInfo.setPassword((int) bldnaDevice.getPassword());
        deviceInfo.setType(bldnaDevice.getType());
        deviceInfo.setLock(false);
        deviceInfo.setAeskey(bldnaDevice.getKey());
        deviceInfo.setTerminalId(bldnaDevice.getId());
        deviceInfo.setSubdeviceNum(1);
        deviceInfo.setWifimac(bldnaDevice.getMac());
        deviceInfo.setLongitude("");
        deviceInfo.setLatitude("");
        deviceInfo.setExtend("");
        return deviceInfo;
    }
}
